package com.evenmo.test;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.evenmo.mapper.OrderMapper;
import com.evenmo.mapper.UserMapper;
import com.evenmo.pojo.Order;
import com.evenmo.pojo.User;
import com.evenmo.util.MySqlSessionFactory;



public class MybatisTest1 {
	private SqlSession session;
	private UserMapper userDao;
	private OrderMapper orderDao;
	private User user;
	private Order order;
	@Before
	public void initDatas() {
		session=getSqlSession();
		userDao=session.getMapper(UserMapper.class);
		orderDao=session.getMapper(OrderMapper.class);
	user=new User();
	order=new Order();

	}
	
	@Test
	public void testQueryByStudentId() {
		user.setId(1);
		User u = userDao.queryByUserId(user);
		System.out.println(u);
	}
	
	@Test
	public void queryUserOfOrdersByUserId() {
		user.setId(1);
		User u = userDao.queryUserOfOrdersByUserId(user);
		System.out.println(u);
	}
	@Test
	public void queryOrderByUserId() {
		order.setUserId(1);
		List<Order> o = orderDao.queryByUserId(order);
		System.out.println(o);
	}
	@Test
	public void queryOrderByOrderId() {
		order.setId(1);
		Order o= orderDao.queryByOrderId(order);
		System.out.println(o);
	}
	
	@Test
	public void queryOrderByOrderId2() {
		order.setId(1);
		Order o= orderDao.queryByOrderId2(order);
		System.out.println(o);
	}
	public static SqlSession getSqlSession() {
		return MySqlSessionFactory.getSqlSession();
	}
	@After
	public void closeSession() {
		session.commit();
		session.close();
	}
	
	

}
